using IM.Easy.Infrastructure.Query;
using Microsoft.AspNetCore.Mvc;
using IM.Easy.LogServices.Dtos;
using IM.Easy.LogServices.IServices;
using IM.Easy.Entity.Log;
using IM.Easy.Core.Attributes;

namespace IM.Easy.Api.Controllers.Log
{
    /// <summary>
    /// UserOnlineLogController 控制器
    /// </summary>
    public class UserOnlineLogController : ControllerBase
    {
        private readonly IUserOnlineLogService _service;

        /// <summary>
        /// 构造函数，注入服务
        /// </summary>
        /// <param name="service">服务接口</param>
        public UserOnlineLogController(IUserOnlineLogService service)
        {
            _service = service;
        }

        /// <summary>
        /// 获取所有UserOnlineLog对象
        /// </summary>
        /// <returns>返回UserOnlineLog列表</returns>
        [HttpGet]
        [Api(Name = "用户在线日志", Perm = "onlinelog:user")]
        public PageResponse<UserOnlineLog> GetList([FromQuery] UserOnlineLogQueryDto query)
        {
            return _service.GetPageList(query);
        }

        /// <summary>
        /// 根据ID获取UserOnlineLog对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <returns>返回指定的UserOnlineLog对象</returns>
        [HttpGet("{id}")]
        [Api(Name = "用户在线日志详情", Perm = "onlinelog:info")]
        public UserOnlineLog GetById([FromRoute] string id)
        {
            var result = _service.GetById(id);
            return result ?? throw new KeyNotFoundException($"未找到ID为 {id} 的UserOnlineLog对象。");
        }

        /// <summary>
        /// 创建新的UserOnlineLog对象
        /// </summary>
        /// <param name="entity">要创建的UserOnlineLog对象</param>
        /// <returns>返回创建后的UserOnlineLog对象</returns>
        [HttpPost]
        public UserOnlineLog Create([FromBody] UserOnlineLog entity)
        {
            _service.Create(entity);
            return entity; // 直接返回创建的实体
        }

        /// <summary>
        /// 更新现有的UserOnlineLog对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        /// <param name="entity">更新后的UserOnlineLog对象</param>
        [HttpPut]
        public void Update([FromBody] UserOnlineLog entity)
        {
            _service.Update(entity);
        }

        /// <summary>
        /// 批量删除UserOnlineLog对象
        /// </summary>
        /// <param name="ids">对象的IDS</param>
        [HttpDelete]
        [Api(Name = "删除用户在线日志", Perm = "onlinelog:del:bulk")]
        public void Delete([FromBody] string[] ids)
        {
            _service.Delete(ids);
        }

        /// <summary>
        /// 单个删除UserOnlineLog对象
        /// </summary>
        /// <param name="id">对象的ID</param>
        [HttpDelete("{id}")]
        [Api(Name = "删除用户在线日志", Perm = "onlinelog:del")]
        public void Delete([FromRoute] string id)
        {
            _service.Delete(id);
        }
    }
}
